<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> 
<html>
<head>
<title>客户信息列表</title>
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="<%=path1%>/qt/yjs/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="<%=path1%>/qt/yjs/bootstrap.min.js"></script>
 

<link rel="stylesheet" type="text/css" href="<%=path1%>/qt/css/normalize.css" />
		<link rel="stylesheet" type="text/css" href="<%=path1%>/qt/fonts/font-awesome-4.2.0/css/font-awesome.min.css" />
		<link rel="stylesheet" type="text/css" href="<%=path1%>/qt/css/demo.css" />
		<link rel="stylesheet" type="text/css" href="<%=path1%>/qt/css/component.css" />
<link href="../css/css.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/redmond/jquery-ui-1.8.2.custom.css"/>
<link type="text/css" rel="stylesheet" href="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/ui.jqgrid.css"/>  


<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.src.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.min.js"></script>  
<link rel="stylesheet" href="<%=path1%>/qt/ycss/bootstrap.min.css">

<!-- 可选的Bootstrap主题文件（一般不用引入） -->
<link rel="stylesheet" href="<%=path1%>/qt/ycss/bootstrap-theme.min.css">
  <script  type="text/javascript">
   function ajaxUpdate123(){
	   var role_id = $('#list4').jqGrid('getGridParam', 'selrow');
		var contract_id= $("#list4").getCell(role_id,"contract_id"); 
     $.ajax({ 	
     data: {
    	 contract_id:contract_id,
     	cheknum:$("#input-1").val()
     	},  
     	type:"Post",  
     dataType: 'json',  
     url:"../qt/contract/checkMassage.do", 
     error:function(data){  
    	alert("系统繁忙，请稍后再试！")
     },  
     success:function(data){
    	  $('#myModal').modal('hide');
    	  jQuery("#list4").trigger("reloadGrid");
       window.location.href = '../qt/contract/exportExcel.do'; 
       
     }
      });  
    
  } 
   function payMent(){
   	var customer_id=$('#list4').jqGrid('getGridParam','selrow');
   	if(customer_id==null)
   	{
   	alert("请选择要修改的行");
   	return;
   	}
      var rowData = $('#list4').jqGrid('getRowData',customer_id);
      updateid=rowData.contract_id;
      window.location.href = "listPayMent.jsp?contract_id="+updateid;
   }
     
     
	function sendMassage() {
		var role_id = $('#list4').jqGrid('getGridParam', 'selrow');
		var contract_id= $("#list4").getCell(role_id,"contract_id"); 
		
		if (contract_id == null) {
			alert("前选择要签约的合同");
			return;
		} else {
		     $.ajax({ 	
		    	 data: {
		    	     	"contract_id":contract_id
		    	     	},  
		         dataType: 'json',  
		         url:"../qt/contract/sendMassage.do", 
		         error:function(data){  
		                 alert("系统繁忙");
		         },  
		         success:function(data){
		           $('#myModal').modal('show');
		           var checstr = "已经发送验证信息到您预留手机号\""+data.rows[0]+"\"，请完成验证！谢谢 。";
		           $('#checkmassageid').html(checstr);
		           }  
		   });  
		}
	}
</script>

<script type="text/javascript">
function unique(arr) {
	  var result = [], hash = {};
	  for (var i = 0, elem; (elem = arr[i]) != null; i++) {
	    if (!hash[elem]) {
	      result.push(elem);
	      hash[elem] = true;
	    }
	  }
	  return result;
	}
$(document).ready(function(){

	  var SearchSql ="GROUP BY first_party,second_party";
			 $.ajax({
				 url:"./contract/selectBySql.do",
				 data:{'SearchSql':SearchSql},
				 success:function(data){
					 var selectscustomerName = document.getElementById("first_party");
			         var selectsOrderType = document.getElementById("second_party");
					 var  firstarr = new Array();
					 var  secondarr = new Array();
					 for(var a=0;a<data.rows.length;a++){
						 firstarr[a]=data.rows[a].first_party;
						 secondarr[a]=data.rows[a].second_party;
					  
					 }
					 var firstarrs = unique(firstarr);
					 var secondarrs = unique(secondarr);
			        for(var c=0;c<firstarrs.length;c++){
			          
			         	var opCustomerName=document.createElement("option");      
			         	opCustomerName.setAttribute("value",firstarrs[c]);        
			         	opCustomerName.appendChild(document.createTextNode(firstarrs[c])); 
			        	selectscustomerName.appendChild(opCustomerName);      
			        	//------------
			        }
			       for(var d=0;d<secondarrs.length;d++){
			    	//   console.log("secondarr:"+secondarrs[d])
			   		var opselectsPayTypeName=document.createElement("option");    
	        		opselectsPayTypeName.setAttribute("value",secondarrs[d]);        
	        		opselectsPayTypeName.appendChild(document.createTextNode(secondarrs[d])); 
	        		selectsOrderType.appendChild(opselectsPayTypeName);  
			       }
			      
				 }
			 });
			
});
function loadorder(){
    sstrval = $("#first_party").val();
	customerNameVal = $("#second_party").val();
	payTypeName = $("#contract_state").val();
	var sstra ='';
	if(!(sstrval == '' || sstrval == null )){
		sstra = "and first_party ='"+sstrval+"'";
	}
	if(!(customerNameVal == '' || customerNameVal == null) ){
		sstra = sstra+ "and second_party ='"+customerNameVal+"'";
	}
	if(!(payTypeName == '' || payTypeName == null )){
		sstra = sstra+ "and contract_state ='"+payTypeName+"'";
	}
	console.log(sstra);
	$("#list4").jqGrid('setGridParam',{
		url:"./contract/selectBySql.do",
		type:"POST",
		postData:{"SearchSql":sstra},
        datatype:'json', 
          }).trigger("reloadGrid"); 

}
</script>
<script type="text/javascript">
$(document).ready(function(){
	var SeachSql;
	var id;
    var str=window.location.href; //得到listclient的地址
    //alert("str"+str);
    var es=/id=/; 
    es.exec(str); //得到地址后面变量名称
    //alert("es--"+es.exec(str));
    var right=RegExp.rightContext;//得到地址后面变量名称的值
    //alert("right-"+right);
  

    $("#list4").jqGrid({
        url:"./contract/selectBySql.do",   //自动查询
        datatype:"json", 
        mtype:"POST",
        height:420,
        autowidth:true,
        colNames:[ 
				'签约时间','合同甲方','合同总价',                  
				'客户编号','客户名称','合同编号','订单编号','签订合同的乙方','业务员编号',                
				'业务员名称','客户购买的房间编号','房间面积','单价','购买的房间总价',            
				'付款方式名称','合同状态','合同内容'
                 ],
       colModel:[
			
			{name:'sign_time',index:'sign_time', width:'15%', align:'center'},
			{name:'first_party',index:'first_party', width:'15%', align:'center'},
			{name:'contract_total',index:'contract_total', width:'15%', align:'center'},
			{name:'customer_id',  hidden:true, index:'customer_id', width:'15%', align:'center'},
			{name:'customer_name',index:'customer_name', width:'15%', align:'center'},
			{name:'contract_id', hidden:true, index:'contract_id', width:'15%', align:'center'},
			{name:'order_id',index:'order_id',hidden:true, width:'15%', align:'center'},
			{name:'second_party',index:'second_party', width:'15%', align:'center'},
			{name:'user_id',index:'user_id',hidden:true, width:'15%', align:'center'},
			{name:'name',index:'name', width:'15%', align:'center'},
			{name:'room_id',index:'room_id',hidden:true, width:'15%', align:'center'},
			{name:'room_area',index:'room_area', width:'15%', align:'center'},
			{name:'unit_price',index:'unit_price', width:'15%', align:'center'},
			{name:'total',index:'total', width:'15%', align:'center'},
			{name:'pay_type_name',index:'pay_type_name', width:'15%', align:'center'},
			{name:'contract_state', hidden:true,index:'contract_state', width:'15%', align:'center' ,formatter:function(value,options,rowData){
                if( value===0 ){
                    return '未签约';
                 }else{
                     return '已签约';
                 }
             }},
			{name:'contract_content',index:'contract_content', width:'15%', align:'center'}    
			],
        rownumbers:true,
        loadComplete: function () { 
        	  if(right==1){
        		   	 console.log("right"+right)
        		   	 window.location.href = "../qt/contract/exportExcel.do";
        		   }
        	  else if(right==2){
        		  
        	  }
        }, 
        //altRows:true,
        //sortname:'createDate',
        //sortorder:'asc',
        viewrecords: true,
        rowNum:5,
      
        multiselect: true,//复选框     
        rowList:[2,4,6,8,10,12],
        jsonReader:{
            id: "blackId",
            repeatitems : false
        },
        pager:$('#gridPager')
    });
});
</script>
<script type="text/javascript">  
 
    function ajaxInsert(){  
        var customer_id=$('#list4').jqGrid('getGridParam','selrow');
        if(customer_id==null)
        	{
        	alert("请选择要查看的行");
        	return;
        	}
        var rowData = $('#list4').jqGrid('getRowData',customer_id);
        delid=rowData.order_id;
         contract_id= rowData.contract_id
         window.location.href = "lookContract.jsp?id="+delid+"&contract="+contract_id;

    }
    
    function ajaxUpdate(){  
    	
    	var customer_id=$('#list4').jqGrid('getGridParam','selrow');
    	if(customer_id==null)
    	{
    	alert("请选择要修改的行");
    	return;
    	}
       var rowData = $('#list4').jqGrid('getRowData',customer_id);
       updateid=rowData.order_id;
       window.location.href="updateOrder.jsp?id="+updateid;
        
     }  
    function ajaxDelete(){  
    	
        var customer_id=$('#list4').jqGrid('getGridParam','selrow');
        if(customer_id==null)
        	{
        	alert("请选择要删除的行");
        	return;
        	}
        var rowData = $('#list4').jqGrid('getRowData',customer_id);
        delid=rowData.contract_id;
         
        $.ajax({   
        data: {contract_id:delid},  
        type:"Post",  
        dataType: 'json',  
         url:"./contract/deleteContract.do",  
         error:function(data){  
             alert("出错了！！");  
         },  
        success:function(data){  
        	$("#list4").jqGrid('setGridParam',{ 
                datatype:'json', 
                postData:{'pageSize':10,'pageIndex':1,'SearchSql':""}, // 发送数据   
                page:1 
            }).trigger("reloadGrid"); 
        	 //alert("success:"+data.msg);  
            // $("#result").html(data.msg) ;  
         }  
         });  
     } 
    function ajaxSelect(){  
     /*   $.ajax({  
        data: {pageSize:10,pageIndex:1,SearchSql:""},  
        type:"Post",  
        dataType: 'json',  
         url:"selectBySql.do",  
         error :function(data){  
             alert("出错了！！");  
         },  
        success:function(data){  
          // alert("success:"+data);  
            // $("#result").html(data[0]);
        }
        }); 
     */
        var SearchSql ="";
        var customer_name=$("#customer_name").val();
        alert(customer_name);
        var tel=$("#tel").val();
        alert(tel);
          if(customer_name=="" && tel=="" ){
        	  SearchSql +="and delete_state='0'"
        	  $("#list4").jqGrid('setGridParam',{ 
                  datatype:'json', 
                  postData:{'SearchSql':SearchSql}, // 发送数据   
                  url:"./Customer/selectBySql.do",
                  page:1 
              }).trigger("reloadGrid"); 
          }else{
        	  if(customer_name!="" )
          	  {
          	     SearchSql +="  and customer_name like '%"+customer_name+"%'";
          	  }
        	  if(tel!="" )  
          	  {
          	     SearchSql +="  and tel='"+tel+"'";
          	  }
          	$("#list4").jqGrid('setGridParam',{ 
              datatype:'json', 
              postData:{'SearchSql':SearchSql}, // 发送数据     //  where name like '%"+$("#name").val()+"%'
              url:"./Customer/selectBySql.do",
              page:1 
          }).trigger("reloadGrid");  
          }
           
     } 
</script> 
<script type="text/javascript">
    function gotoaddreceive(){
    	var customer_id=$('#list4').jqGrid('getGridParam','selrow');
    	if(customer_id==null)
    	{
    	alert("请选择要修改的行");
    	return;
    	}
       var rowData = $('#list4').jqGrid('getRowData',customer_id);
       updateid=rowData.contract_id;
       console.log(updateid)
    	 $.ajax({
			 url:"./contract/updateContractState.do",
			 data:{'contract_id':updateid},
			 success:function(data){
				window.location.href="listContract.jsp" 
			 }
			 });
    }
    
</script>
</head>
<body>
<div id="gridPager"></div>
<div class="yboxwidth boxcenter ybox01" style="width: 100%">
<div class="ybox09" style="width: 100%" >
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <td  style="padding-left: 30px ">
       <table width="100%"  border="0"  cellspacing="0" cellpadding="0">
          <tr valign="top">
            <td class="ybox11td5" ></td>
            <td class="ybox11td6" >合同管理</td>
            <td class="ybox11td7"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td4"></td>    
             <td class="ybox11td4"></td>   
               <td class="ybox11td4"></td>   
                 <td class="ybox11td4" ></td>    
          </tr>
        </table>
        </td>
        </tr>
    </table>
  </div>
  
  <div class="ybox02">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="margb4">
      <tr>
        <td class="ybox03td1"></td>
        <td class="ybox03td2"></td>
        <td class="ybox03td3"></td>
      </tr>
      <tr>
        <td class="ybox03td4"></td>
        <td class="ybox03td5"><div class="ybox05 margb8">
          <dl>
            <dt> <strong></strong>&nbsp;&nbsp;
               <!--   订单单号：<input type="text" id="customer_name"/> &nbsp;&nbsp;&nbsp;&nbsp; -->  
	               甲方名称：<select style="width: 150px;" id="first_party" onchange="loadorder()">
	         <option value="">全部</option>
	        </select>
                        乙方名称：<select style="width: 150px;" id="second_party" onchange="loadorder()">
	         <option value="">全部</option>
	        </select>
	                订单状态：<select style="width: 150px;" id="contract_state" onchange="loadorder()">
	         <option value="">全部</option>
	         <option value="0">未签约</option>
	         <option value="1">已签约</option>
	        </select>
	       <img onclick="ajaxSelect()" src="images/bottonselect.gif" width="50" height="20" style="vertical-align: middle;cursor: pointer;" />
	           </dt>
          </dl>
        </div>
          <div class="ybox07 margb2">
            
      <dl><table border="0" cellspacing="0" cellpadding="0" class="ybox07table" width="100%">
              <tr align="left">
                <td class="ybox07td1"><img src="images/op4_1.gif" /></td>
                <td><span style="cursor:pointer;" onclick="ajaxInsert()">查看合同信息</span></td>
                <td class="ybox07td2" width="10px"><img src="images/op4_0.gif" /></td>
                <td class="ybox07td1"><img src="images/op4_3.gif" /></td>
                <td><span style="cursor:pointer;" onclick="ajaxDelete()">移除合同信息</span></td>
                <td class="ybox07td2" width="72%"><img src="images/op4_0.gif" /></td>
                <td class="ybox07td2"><img src="images/op4_0.gif" /></td>
                <td class="ybox07td1" ><img src="images/op6_1.gif" width="15" height="16"/></td>
                <td ><span style="cursor:pointer;" onclick="payMent()" >查看缴费记录</span></td>
                <!-- gotoaddreceive() -->
                <td class="ybox07td2" ><img src="images/op4_0.gif"  /></td>
               
              </tr>
          </table>
          </dl>
          </div>	
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="ybox06table" id="list4">
                
          </table>
        
        <td class="ybox03td6"></td>
      </tr>
      <tr>
        <td class="ybox03td7"></td>
        <td class="ybox03td8"></td>
        <td class="ybox03td9"></td>
      </tr>
    </table>
  </div>
</div>

   <!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
  <div class="modal-dialog" role="document">
    <div class="modal-content" style="height: 400px; width: 420px">
      <div class="modal-header" style="background:#438eb9;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">验证签约信息</h4>
      </div>
   
      <div class="modal-body">
 <div class="form-group" >
     <div id="massageid" style="width: 80%">
          <label for="inputEmail3"  class="col-sm-2 control-label" style="width: 100%">
           <b><h3>短信验证</h3></b><br/>
             <font id="checkmassageid">
             
             </font>
         </label>
    </div>
     </div>
     </div>
  <!--  <div class="col-sm-10">
     验证码： <input type="text" class="form-control" id="role_name" placeholder="role_name"/>
    </div>
 --> 
            <span class="input input--haruki">
			<input class="input__field input__field--haruki" type="text" id="input-1" />
			<label class="input__label input__label--haruki" for="input-1">
				<span class="input__label-content input__label-content--haruki">请输入验证码</span>
			</label>
		</span>
 
      
       <div class="modal-footer">
        <input type="button" onclick="ajaxUpdate123()" value="　提　交 　" class="btn btn-success"/>
        <button type="button" class="btn btn-success" onclick="sendMassage()">　重新发送　</button>
      </div>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font >
                   如果60秒内没有接收到消息，请点击重新发送。
      </font>

    </div>
  </div>
</div>



<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
  <div class="modal-dialog" role="document">
    <div class="modal-content" style="height: 500px; width: 420px">
      <div class="modal-header" style="background:#438eb9;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">验证签约信息</h4>
      </div>
   
      <div class="modal-body">
 <div class="form-group" >
     <div id="massageid" style="width: 80%">
          <label for="inputEmail3"  class="col-sm-2 control-label" style="width: 100%">
           <b><h3>短信验证</h3></b><br/>
             <font id="checkmassageid">
             
             </font>
         </label>
    </div>
     </div>
     </div>
  <!--  <div class="col-sm-10">
     验证码： <input type="text" class="form-control" id="role_name" placeholder="role_name"/>
    </div>
 --> 
            <span class="input input--haruki" style="height:50px;" >
			<input class="input__field input__field--haruki" type="text" id="input-1" />
			<label class="input__label input__label--haruki" for="input-1">
				<span class="input__label-content input__label-content--haruki">请输入验证码</span>
			</label>
		</span>
 
      
       <div class="modal-footer">
        <input type="button" onclick="ajaxUpdate123()" value="　提　交 　" class="btn btn-success"/>
        <button type="button" class="btn btn-success" onclick="gopayMant()">　重新发送　</button>
      </div>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font >
                   如果60秒内没有接收到消息，请点击重新发送。
      </font>

    </div>
  </div>
</div>
</body>
</html>